/**
 * 广寒宫
 * 网址:www.guanghangong.xyz
 */
package com.moon.admin.sys.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moon.admin.sys.entity.SysMenuEntity;

/**
 * 菜单DAO
 * @author ninglong
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenuEntity>{

	/**
	 * 获取一个用户的菜单
	 * @param userId 用户id
	 * @return 菜单列表
	 */
	@Select(value = "SELECT m.id,m.menuName,m.parentId,m.url,m.menuType,m.perms,m.icon,m.moduleId from sys_menu m LEFT JOIN sys_role_menu rm on(m.id=rm.menuId) WHERE m.deleted=0 and rm.deleted=0 and rm.roleId in(SELECT roleId from sys_user_role WHERE userId=#{userId} and deleted=0)")
	List<SysMenuEntity> getMenuListByUserId(Integer userId);
	
	/**
	 * 根据父菜单所顶部菜单修改子菜单的所属
	 */
	@Update(value="update sys_menu set moduleId=#{moduleId} where parentId=#{parentId}")
	void batchUpdateMenuPlatformByParentId(@Param("moduleId")Integer moduleId,@Param("parentId")Integer parentId);
}
